mui.init();
var tex = document.getElementById("tex");
var biaoqian = document.getElementById("biaoqian");

var demo = new Vue({
	el: '#main',
	data: {
		notshow: false,
		tageslist: [],
		selectedTag: []
	},
	methods: {
		addtag: addtag
	},
	ready: function() {
		var getTagUrl = getUrl("61getTag");
		var getTagHeader = getHeader();
		var accountid = readData(localStorage.accountnum);
		datas = "accountId=" + readData(localStorage.accountnum) + "&createAccountId=" + readData(localStorage.account) + "&userId=" + readData(localStorage.guideId);
		this.$http({
			url: getTagUrl,
			method: 'POST',
			headers: getTagHeader,
			data: datas,
			timeout: 10000
		}).then(function(respons) {
			console.log(JSON.stringify(respons.data));
			if (respons.data.code == "0") {
				if (!respons.data.obj || !respons.data.obj.list) {
					var show = true;
					this.$set('notshow', show);
					return;
				} else {
					this.$set('notshow', false);
					var list = respons.data.obj.list;
					var selected = [];
					for (var i in list) {
						if (list[i].flag == "0") {
							list[i].disabled = "false";
						} else {
							list[i].disabled = "true";
							selected.push(list[i]);
						}
					}
					this.$set('selectedTag', selected);
					this.$set('tageslist', list);
				}
			}
		}, function() {
			console.log('网络链接异常')
		})
	}
});

function addtag(tId, tname) {
	var addUrl = getUrl("50addTag");
	var addHeader = getHeader();
	var accountid = readData(localStorage.accountnum);
	var datas;
	//被打标签顾客或导购id
	if (readData(localStorage.usertype) == "2") {
		datas = 'createAccountId=' + readData(localStorage.account) + '&tagId=' + tId + "&accountId=" + readData(localStorage.accountnum) + "&circleId=" + readData(localStorage.circleId);
	} else {
		datas = 'createAccountId=' + readData(localStorage.account) + '&tagId=' + tId + "&userId=" + readData(localStorage.accountnum) + "&circleId=" + readData(localStorage.circleId);
	}
	demo.$http({
		url: addUrl,
		method: 'POST',
		headers: addHeader,
		data: datas,
		timeout: 10000
	}).then(function(respons) {
		if (respons.data.code == "0") {
			demo.selectedTag.push(tname);
			add(tId);
		} else {
			mui.toast(data.msg);
		}
	}, function() {
		console.log("网络链接异常");
	})
}

function add(tid) {
	var list = plus.webview.getWebviewById('friendDetail.html');
	mui.fire(list, 'add');
	document.getElementById(tid).disabled = "true";
}